<template>
  <button @click="logOut">
    下线
  </button>
  <el-input v-model="newPwd" placeholder="Please input" clearable/>
  <el-button @click="changePwd" type="primary">修改密码</el-button>
</template>

<script>
import $store from '../store/index'
import axios from "axios";
export default {
  name: "userInfo",
  setup(){
    function setLoged(log) {
      $store.dispatch('setLog',log);
    }
    return{
      setLoged
    }
  },
  data() {
    return{
      newPwd:''
    }
  },
  methods: {
    logOut() {
      this.$store.commit('setLoged', false)
      window.localStorage.removeItem("zjxClass_student_info")
      this.$router.push({name: 'Index'})
    },
    changePwd(){
      axios.get("/api/StudentChangePassword",{
        params:{
          newPwd:this.newPwd
        }
      }).then((res)=>{
        if (res.status===200&&res.data==='changeSuccess'){
          alert("ok")
          this.setLoged(false)
          window.localStorage.removeItem("zjxClass_student_info")
          this.$router.push({name: 'Index'})
        }
      })
    }
  }
}
</script>

<style scoped>


</style>